/**
 * Project		:	TAO Library
 * Created		:	17 февр. 2014 г.
 * Author		:	Alexandr Tsvetkov
 */
package ua.at.tsvetkov.webservices.parsers;

import android.os.Handler;
import android.os.Message;

/**
 * @author Alexandr Tsvetkov
 */
public abstract class AbstractWebHandler extends Handler {

	public static final int	PARSE_SUCCESS	= 0;
	public static final int	PARSE_ERROR		= -1;

	/*
	 * (non-Javadoc)
	 * @see android.os.Handler#handleMessage(android.os.Message)
	 */
	@Override
	public void handleMessage(Message msg) {
		if (msg.what == PARSE_SUCCESS)
			onSuccess();
		if (msg.what == PARSE_ERROR)
			onError();
	}

	/**
	 * Send success message to main thread.
	 */
	public void sendSuccessMessage() {
		sendEmptyMessage(PARSE_SUCCESS);
	}

	/**
	 * Send error message to main thread.
	 */
	public void sendErrorMessage() {
		sendEmptyMessage(PARSE_ERROR);
	}

	/**
	 * Called when handler received success message in main thread.
	 */
	public abstract void onSuccess();

	/**
	 * Called when handler received error message in main thread.
	 */
	public abstract void onError();

}
